<template>
  <div class="profile-container">
    <div class="title-container">
      <div class="title">{{ name }}</div>
    </div>
    <div class="echarts-container">
      <div class="top">
        <el-row :gutter="20">
          <el-col :span="16">
            <el-card shadow="always"><total-charts :config="sInfo" /></el-card>
          </el-col>
          <el-col :span="8">
            <el-card shadow="always"><position-charts :config="sInfo" /></el-card>
          </el-col>
        </el-row>
      </div>
      <div class="bottom">
        <el-row :gutter="20" style="margin-top: 30px">
          <el-col :span="8" style="height: 100%"
            ><el-card><equipment-chart :config="sInfoEq" /></el-card
          ></el-col>
          <el-col :span="8"
            ><el-card><system-chart :config="sInfoSys" /></el-card
          ></el-col>
          <el-col :span="8"
            ><el-card><way-chart :config="sInfoWec" /></el-card
          ></el-col>
        </el-row>
      </div>
    </div>
  </div>
</template>

<script>
import PositionCharts from './positionCharts.vue'
import totalCharts from './totalCharts'
import equipmentChart from './equipmentChart'
import systemChart from './systemChart'
import wayChart from './wayChart'
import { getFormData } from '@/api/form'
import {findFormJsonOne} from "../../../api/form";
export default {
  name: 'Profile',
  components: {
    totalCharts,
    PositionCharts,
    equipmentChart,
    systemChart,
    wayChart
  },
  computed:{
    name(){
      return localStorage.getItem('title') || '默认标题'
    }
  },
  data() {
    return {
      fid: null,
      sInfo:{},
      sInfoEq:{},
      sInfoSys:{},
      sInfoWec:{}
    }
  },
  mounted() {
    this.fid = this.$route.query.id
    this.getFormDataHandle()
  },
  methods: {
    async getFormDataHandle() {
      const { data } = await getFormData(this.fid)
      console.log(data)
      let sInfo = data.data;
      const res = await findFormJsonOne(this.fid)
      console.log('表单模型',res)
      sInfo.model = res.data.data;
      this.sInfo = sInfo;
      console.log('sInfo',sInfo)
      //初始化系统数据
      this.sInfoEq = {'PC':this.sInfo.data.filter((e)=> e.client == 'PC端').length,'Mobile':this.sInfo.data.filter((e)=> e.client == '移动端').length}
      //初始化系统数据
      this.sInfoSys = {
        'Android':this.sInfo.data.filter((e)=> e.os == 'Linux').length,
        'iOS':this.sInfo.data.filter((e)=> e.os == 'Unix').length,
        'Win':this.sInfo.data.filter((e)=> e.os.indexOf('Win') >= 0).length,
        'Mac':this.sInfo.data.filter((e)=> e.os == 'Mac').length,
        'Other':this.sInfo.data.filter((e)=> e.os == 'other').length,
      }
      this.sInfoWec = {
        'true':this.sInfo.data.filter((e)=> e.wechat == true).length,
        'false':this.sInfo.data.filter((e)=> e.wechat == false).length
      }
      console.log('传值',this.sInfoEq)
      console.log('传值',this.sInfoSys)
    }
  }
}
</script>

<style scoped lang="scss">
.profile-container {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  margin-top: 30px;
  .title-container {
    display: flex;
    align-items: center;
    .title {
      font-size: 18px;
      font-weight: 500;
      line-height: 26px;
      margin-right: 20px;
    }
    .subtext {
      padding: 6px;
      line-height: 20px;
      font-size: 12px;
      box-shadow: 0 0 0 1px #bbb;
      border-radius: 20px;
      line-height: 20px;
    }
  }
  .echarts-container {
    height: 100%;
    width: 100%;
    display: flex;
    flex-direction: column;
    margin-top: 30px;
    .top {
      height: 520px;
      width: 100%;
      margin-right: 90px;
    }
    .bottom {
      height: 520px;
      width: 100%;
    }
  }
}
</style>
